<?php
	class Admin_UploadController extends Zendvn_Controller_Action{
		
		
		
		
		
		public function init(){
			
			
			$template_path= TEMPLATE_PATH. '/admin/upload';
			$this->loadTemplate($template_path, 'template.ini', 'template');
		}
		
		public function indexAction() {
			
			//iploadify
			$this->view->headLink()->appendStylesheet(PUBLIC_URL . "/scripts/uploadify/uploadify.css",'screen');
			$this->view->headScript()->appendFile(PUBLIC_URL . "/scripts/uploadify/swfobject.js",'text/javascript');
			$this->view->headScript()->appendFile(PUBLIC_URL . "/scripts/uploadify/jquery.uploadify.v2.1.4.min.js",'text/javascript');

			$this->view->upload= 'active';
			
		}
		
		
		public function uploadifyAction() {
			//echo __METHOD__;
			if (!empty($_FILES)) {
				$uploadDir=PUBLIC_PATH.'/files/images/';
				$upload = new Zendvn_File_Upload();
				$fnimage   =    $upload->upload('full_image',$uploadDir.'full_images/',array('task'=>'rename'));
				 
				//luu vao csdl
				/*
				$this->_arrParam['title']      =   $_FILES['full_image']['name'];
				$this->_arrParam['cat_id']      =   $this->_arrParam['cat_id'];
				$this->_arrParam['full_image']   =   $fnimage;
				$tblPhoto=new Photo_Model_Photo();
				$tblPhoto->saveItem($this->_arrParam,array('task'=>'admin-add'));
				*/
				//Resize
				$linkImage=$uploadDir . 'full_images/'. $fnimage;
				$img = Zendvn_File_Image::create($linkImage);
				$img->resize(500,500);
				$img->save($uploadDir . 'thumb_images_500x500/' . $fnimage);
				//Resize
				$linkImage=$uploadDir . 'full_images/'. $fnimage;
				$img = Zendvn_File_Image::create($linkImage);
				$img->resize(200,200);
				$img->save($uploadDir . 'thumb_images_200x200/' . $fnimage);
				//crop image
				$linkImage=$uploadDir . 'thumb_images_500x500/'. $fnimage;
				$img = Zendvn_File_Image::create($linkImage);
				//lay chieu dai va chieu cao cua anh
				$imgSize=getimagesize($linkImage);
				$cropImg = $imgSize[0];
				if($cropImg>$imgSize[1])
					$cropImg=$imgSize[1];
				$img->cropFromCenter($cropImg,$cropImg)
				->resize(75,75);
				$img->save($uploadDir . 'crop_images/' . $fnimage);
				echo $fnimage;
			}
			$this->_helper->layout->disableLayout();
			$this->_helper->viewRenderer->setNoRender();
		}
		
		public function writebookAction(){
			
			
			$this->view->title= 'Book:: WriteBook';
			$this->view->writebook= 'active';
			
			//Zend_Debug::dump($this->CmsEditor('name', ''));
			
		}
		
		
	}